package com.tjetc.controller;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tjetc.common.FileUploadInfo;
import com.tjetc.common.FileUploadUtils;
import com.tjetc.common.JsonResult;
import com.tjetc.service.AreaService;
import com.tjetc.service.CategoryService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UtilsController {
        @Autowired
        private AreaService areaService;
        @Autowired
        private FileUploadInfo fileUploadInfo;
        @Autowired
        private CategoryService categoryService;

        //商家端上传图像
        @RequestMapping("merchant/upload")
        public JsonResult upload(@RequestParam("file")MultipartFile file){
                //上传店铺头像
               return FileUploadUtils.upload(file,fileUploadInfo.getImageBasePath(),"image");
        }

        //获得地区的子地区列表
        @RequestMapping("test")
        public JsonResult getArea(@RequestParam("id")String sid){
                //获得省市区中对应的子级目录
                int id=Integer.parseInt(sid);
                return new JsonResult<>(0,"查询成功",areaService.getAllChildByPid(id, 2));
        }

        //根据菜品一级分类的id获得菜品的二级分类
        @RequestMapping("merchant/getCategory")
        public JsonResult getCategory(String typeId){
                return new JsonResult(0,"查询成功",categoryService.selectByTypeId(Integer.valueOf(typeId)));
        }
}
